package com.linglan.common.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
public class MySaInterceptor implements HandlerInterceptor {
    private SaInterceptor saInterceptor;

    public MySaInterceptor() {
        saInterceptor = new SaInterceptor(handle -> StpUtil.checkLogin());
    }

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String requestURI = request.getRequestURI();
        log.info("requestUrl={}", request.getRequestURL());
        log.info("method={}", request.getMethod());
        return saInterceptor.preHandle(request, response, handler);
    }
}
